package com.zhxh.nzpos.sell;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

import com.zhxh.nzpos.Constants;
import com.zhxh.nzpos.R;
import com.zhxh.nzpos.TestData;
import com.zhxh.nzpos.dao.BuyinDao;
import com.zhxh.nzpos.model.Buyin;
import com.zhxh.nzpos.model.Goods;
import com.zhxh.nzpos.model.Sellout;
import com.zhxh.nzpos.utils.ViewUtil;

/**
 * 商品销售中的进货信息界面
 * 
 * @author wangzt
 *
 */
public class BuyinInfoActivity extends Activity {

	private ArrayList<Buyin> buyinItems;
	private BuyinInfoListAdapter listAdapter;
	
	private BuyinDao buyinDao;
	private long total;
	private int pageSize = 6;
	private int currentPage = 1;
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sell_buyin_info);
        buyinDao = new BuyinDao(getApplicationContext());
        initViews();
    }
	
	private void initViews() {
		buyinItems = new ArrayList<Buyin>();
		total = buyinDao.getCount();
		if (pageSize > total) {
			buyinItems.addAll(buyinDao.getScrollData(currentPage, (int) total));
		} else {
			buyinItems.addAll(buyinDao.getScrollData(currentPage, pageSize));
		}
		
		ListView listView = (ListView) findViewById(R.id.buyin_info_listview);
		
		listAdapter = new BuyinInfoListAdapter(getLayoutInflater(), buyinItems);
		listView.setAdapter(listAdapter);
		
		Button pageupBtn = (Button) findViewById(R.id.buyin_info_up_btn);
		pageupBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				int page = currentPage - 1;
				if (page > 0) {
					buyinItems.clear();
					buyinItems.addAll(buyinDao.getScrollData(page, pageSize));
					currentPage = page;
					listAdapter.notifyDataSetChanged();
				}
			}
		});
		Button pagedownBtn = (Button) findViewById(R.id.buyin_info_down_btn);
		pagedownBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				int page = currentPage + 1;
				if ((total - page * pageSize) > 0) {
					buyinItems.clear();
					buyinItems.addAll(buyinDao.getScrollData(page, pageSize));
					currentPage = page;
					listAdapter.notifyDataSetChanged();
				}
			}
		});
		Button backBtn = (Button) findViewById(R.id.buyin_info_back_btn);
		backBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});
	}
	
	
}
